package com.zhiwang.xiaoqu.ui.coupon

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.RecyclerView
import com.zhiwang.xiaoqu.R
import com.zhiwang.xiaoqu.ktextension.setImmersive
import com.zhiwang.xiaoqu.widget.TaskViewGroup
import kotlinx.android.synthetic.main.activity_daily_check_in.*

class DailyCheckInActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        window.setImmersive(Color.TRANSPARENT, light = false)
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_daily_check_in)
        setSupportActionBar(toolbar)
        taskGroup.setTasks(
            arrayListOf(

                TaskViewGroup.DailyTask(
                    "https://ali-fir-pro-icon.fir.im/705aa5ef7ac391754c6ff26e702acdada427a3b1?auth_key=1567153812-0-0-993aef12f158943d80fe9709050958e1&tmp=1567152012.987424",
                    true,
                    "已完成"
                )
                ,
                TaskViewGroup.DailyTask(
                    "https://ali-fir-pro-icon.fir.im/8c626b6b67bac1a32f60a068d0cd5979e0970aa2?auth_key=1567153812-0-0-85c017237d9c39399bfb5a15f357fb96&tmp=1567152012.9881425",
                    true,
                    "已完成"
                )
                ,
                TaskViewGroup.DailyTask(
                    "",
                    false,
                    "未完成"
                )
                ,
                TaskViewGroup.DailyTask(
                    "",
                    false,
                    "未完成"
                )
                ,
                TaskViewGroup.DailyTask(
                    "",
                    false,
                    "未完成"
                )
            )
        )

        recyclerView.adapter = DailyCheckTaskAdapter()

        nested_scroll_view.setOnScrollChangeListener { v: NestedScrollView?, scrollX: Int, scrollY: Int, oldScrollX: Int, oldScrollY: Int ->

            title_layout.alpha =
                Math.max(0f, Math.min(1f, 1f - scrollY.toFloat() / (redPacketText.top - title_layout.height)))
        }
    }

    override fun onSupportNavigateUp(): Boolean {
        onBackPressed()
        return true
    }


    inner class DailyCheckTaskAdapter : RecyclerView.Adapter<DailyTaskViewHolder>() {

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DailyTaskViewHolder {
            return DailyTaskViewHolder(layoutInflater.inflate(R.layout.item_daily_task, parent, false))
        }

        override fun getItemCount() = 26

        override fun onBindViewHolder(holder: DailyTaskViewHolder, position: Int) {


        }

    }


    class DailyTaskViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val gameIcon = itemView.findViewById<ImageView>(R.id.iv_game_icon)
        val gameReward = itemView.findViewById<TextView>(R.id.tv_reward)
        val gameName = itemView.findViewById<TextView>(R.id.tv_game_name)
        val doTaskButton = itemView.findViewById<TextView>(R.id.tv_do_game_task)
    }
}
